<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function test(fn){
            var cache = {}

            return function(){
                var arg = JSON.stringify(arguments);

                cache[arg] = cache[arg] ? cache[arg] + '(来自缓存池)' : fn.apply(fn, arguments); // 这里就要用apply
                return cache[arg];
            }
        }

        var add = test(function(){
            // 如果不传实参arguments
            var argLen = arguments.length,
                item,
                res = 0;
            for (var i = 0; i < argLen; i++){
                item = arguments[i];
                res += item;
            }
            return res;
        })
        console.log(add(1, 2));
        console.log(add(1, 2));
        console.log(add(1, 3));
        console.log(add(1, 3));
        console.log(add(1, 4));
    </script>
</body>
</html>